package cn.lg.soar.message.feign.fallback;

import cn.lg.soar.message.api.model.MailDTO;
import cn.lg.soar.message.feign.MailApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.time.Duration;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.message.client.MailApiClient")
public class MailApiFallbackFactoryFactory implements FallbackFactory<MailApiFeign> {

    protected static final Logger LOGGER = LoggerFactory.getLogger(MailApiFallbackFactoryFactory.class);

    @Override
    public MailApiFeign create(Throwable cause) {
        return new MailApiFeign() {
            @Override
            public void send(MailDTO mail) {
                LOGGER.error("send: {}", mail, cause);
            }

            @Override
            public void sendCaptcha(String email, String subject, Duration expire, String captcha) {
                LOGGER.error("sendCaptcha: email={}, subject={}，captcha={}", email, subject, captcha, cause);
            }

            @Override
            public boolean checkCaptcha(String email, String captcha, Boolean delete) {
                LOGGER.error("checkCaptcha：email={}，captcha={}", email, captcha, cause);
                return false;
            }
        };
    }
}
